<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Full Layout - jQuery EasyUI Demo</title>
	<#include "./../common/header.html"/>
</head>
<body class="easyui-layout">
	<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:70%"
		data-options="
				title:'调度策略信息',
				singleSelect: true,
				url:'${ctx}/schedule/loadScheduleStrategy',
				toolbar: '#tb',
				pageSize:10,
				pagination:true,
				pageNumber:1,
			">
		<thead>
			<tr>
				<th data-options="field:'strategyName',width:150">策略名称</th>
				<th data-options="field:'sts',width:100">任务状态</th>
				<th data-options="field:'kind',width:150">任务类型</th>
				<th data-options="field:'taskParameter',width:100">任务参数</th>
				<th data-options="field:'taskName',width:100">任务名称</th>
				<th data-options="field:'iplist',width:200">IP地址(逗号分隔)</th>
				<th data-options="field:'numOfSingleServer',width:150">单JVM最大线程组数量</th>
				<th data-options="field:'assignNum',width:100">最大线程组数量</th>
			</tr>
		</thead>
	</table>

	<table id="strategyRunntime" class="easyui-datagrid" title="" style="width:100%;height:28%"
		data-options="
				title:'任务在各个机器上的分配情况',
				singleSelect: true,
				url:'',
			">
		<thead>
			<tr>
				<th data-options="field:'strategyName',width:150">策略名称</th>
				<th data-options="field:'uuid',width:400">处理机器</th>
				<th data-options="field:'requestNum',width:100">线程组数量</th>
				<th data-options="field:'message',width:200">错误信息</th>
			</tr>
		</thead>
	</table>
	
	<div id="tb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="add_scheduleStrategy()">创建新策略</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="edit_scheduleStrategy()">修改策略</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" onclick="del_scheduleStrategy()">删除策略</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editsts_scheduleStrategy()">停止/恢复</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="load_StrategyRunntime()">查看任务分配情况</a>
	</div>

	<div id="add_dlg" class="easyui-dialog" closed="true" data-options="width:700,height:500">
		<div id="content">
		
			<form id="scheduleStrategyForm" method="get" name="scheduleStrategyForm" >
<input type="hidden" name="action" value="<%=actionName%>"/>
<table>
<tr>
	<td>策略名称:</td>
	<td><input type="text"  data-options="required:true"  class="easyui-textbox " id="strategyName" name="strategyName"  value="" width="30" /></td>
	<td>必须填写，不能有中文和特殊字符</td>
</tr>
<tr>
	<td>任务类型:</td>
	<td><input type="text" data-options="required:true"  class="easyui-textbox"  id="kind" name="kind"   value="Schedule" width="30"></td>
	<td>可选类型：Schedule,Java,Bean 大小写敏感</td>
</tr>
<tr>
	<td>任务名称:</td>
	<td><input type="text" data-options="required:true" class="easyui-textbox"  id="taskName" name="taskName"  value="" width="30"></td>
	<td>与任务类型匹配的名称例如：1、任务管理中配置的任务名称(对应Schedule) 2、Class名称(对应java) 3、Bean的名称(对应Bean)</td>
</tr>
<tr>
	<td>任务参数:</td>
	<td><input type="text"  class="easyui-textbox" id="taskParameter" name="taskParameter"   value="" width="30"></td>
	<td>逗号分隔的Key-Value。 对任务类型为Schedule的无效，需要通过任务管理来配置的</td>
</tr>

<tr>
	<td>单JVM最大线程组数量:</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="numOfSingleServer" value="0" width="30"></td>
	<td>单JVM最大线程组数量，如果是0，则表示没有限制.每台机器运行的线程组数量 =总量/机器数 </td>
</tr>
<tr>
	<td>最大线程组数量：</td>
	<td><input type="text" data-options="required:true" class="easyui-numberbox" data-options="min:0,precision:0"  name="assignNum" value="1"  width="30"></td>
	<td>所有服务器总共运行的最大数量</td>
</tr>
<tr>
	<td>IP地址(逗号分隔)：</td>
	<td><input type="text" data-options="required:true" class="easyui-textbox"  name="IPList" value="127.0.0.1" width="30"></td>
	<td>127.0.0.1或者localhost会在所有机器上运行</td>
</tr>
</table>
</form>
		</div>
	</div>

</body>
<script>

function add_scheduleStrategy(){
	$("#strategyName").parent().next().text("必须填写，不能有中文和特殊字符");
	$("input[name='strategyName']").prev().removeAttr("readonly");
	$('#add_dlg').dialog({
		title:'添加调度策略',
		closed: false,
		cache: false,
		buttons:[{ 
			text:'提交', 
			iconCls:'icon-ok',
			handler:function(){
				$("#add_dlg").find('#scheduleStrategyForm').form('submit',{
					onSubmit:function(){
					$("#scheduleStrategyForm").attr('action', '${ctx}/schedule/createScheduleStrategy');
					var flag = $(this).form('validate');
						return flag;
					},
					dataType:"json",
					success : function(response) {
						if(response=='true'){
							$.messager.alert({
								title : '提示',
								msg : "操作成功"
							});
						}else{
							$.messager.alert({
								title : '提示',
								msg : "操作失败："+response
							});
						}
						$('#add_dlg').dialog('close');
						$('#dg').datagrid('reload'); 
					}
				});
				
			} 
		},{ 
			text:'关闭', 
			handler:function(){ 
				$('#add_dlg').dialog('close');
			} 
		}], 
		onOpen:function(){ 
			//$('#add_contentt_dlg_{$rbtId}').dialog('refresh', '__URL__/toAddInfoForm&rbtId={$rbtId}'); 
		} 
	});
}


function del_scheduleStrategy(){
	var row = $("#dg").datagrid('getSelected'); 
	if(row!=null){
		$.messager.confirm('删除?', '确认删除?', function(r){
			if(r){
				$.ajax({ url: "${ctx}/schedule/delScheduleStrategy?strategyName="+row.strategyName, success: function(response){
					if(response=='true'){
							$.messager.alert({
								title : '提示',
								msg : "操作成功"
							});
					}else{
							$.messager.alert({
								title : '提示',
								msg : "操作失败："+response
							});
						}
					$('#dg').datagrid('reload'); 
					
				}});
			}
		});
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

function edit_scheduleStrategy(){
	var row = $("#dg").datagrid('getSelected'); 
	if(row!=null){
		$("#scheduleStrategyForm").form('load',row);
		$("#strategyName").parent().next().text("策略名称,不可更改");
		$("input[name='strategyName']").prev().attr("readonly","true");
		$("input[name='IPList']").prev().val(row.iplist);
		$("input[name='IPList']").prev().focus(function(){
			$("input[name='IPList']").prev().val(row.iplist);
		});
		$('#add_dlg').dialog({
			title:'修改策略',
			closed: false,
			cache: false,
			buttons:[{ 
				text:'提交', 
				iconCls:'icon-ok',
				handler:function(){
					$("#add_dlg").find('#scheduleStrategyForm').form('submit',{
						onSubmit:function(){
							$("#scheduleStrategyForm").attr('action', '${ctx}/schedule/editScheduleStrategy');
							var flag = $(this).form('validate');
							return flag;
						},
						dataType:"json",
						success : function(response) {
							if(response=='true'){
								$.messager.alert({
									title : '提示',
									msg : "操作成功"
								});
							}else{
								$.messager.alert({
									title : '提示',
									msg : "操作失败："+response
								});
							}
							$('#add_dlg').dialog('close');
							$('#dg').datagrid('reload'); 
						}
					});
				} 
			},{ 
				text:'关闭', 
				handler:function(){ 
					$('#add_dlg').dialog('close');
				} 
			}] 
		});
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

function editsts_scheduleStrategy(){
	var row = $("#dg").datagrid('getSelected'); 
	if(row!=null){
		$.ajax({ url: "${ctx}/schedule/editstsScheduleStrategy?strategyName="+row.strategyName+"&sts="+row.sts, success: function(response){
				$('#dg').datagrid('reload'); 
			}
		});
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}

function load_StrategyRunntime(){
	var row = $("#dg").datagrid('getSelected'); 
	if(row!=null){
		 var handler='${ctx}/schedule/loadScheduleStrategyRunntime?strategyName='+row.strategyName;
		 $('#strategyRunntime').datagrid('options').url = handler;
         $('#strategyRunntime').datagrid('reload');
	} else {
		$.messager.alert({
			title : '提示',
			msg : "请选择一行"
		});
	}
}
</script>
</html>

